import { sys } from "cc";
import { JSB } from "cc/env";
import { BasePlatform, Platform } from "../base/BasePlatform";
import { BytedancePlatform } from "../platform/ByteDancePlatform";
import { EditorPlatform } from "../platform/EditorPlatform";
import { WechatPlatform } from "../platform/WechatPlatform";
export class PlatformManager {
    private static _instance: PlatformManager;
    private currentPaltform: BasePlatform;
    public static getInstance(): PlatformManager {
        if (this._instance == null) {
            this._instance = new PlatformManager();
        }
        return this._instance;
    }
    /** 打包的时候需要替换 当前平台 */
    public static currentPlatform = Platform.WECHAT;//WECHAT  EDITOR
    public init() {
        switch (sys.platform) {
            case sys.Platform.BYTEDANCE_MINI_GAME:
                this.currentPaltform = new BytedancePlatform()
                break;
            case sys.Platform.WECHAT_GAME:
                this.currentPaltform = new WechatPlatform()
                break;
            default:
                // if (PlatformManager.currentPlatform == Platform.WEB_LINK) {
                //     this.currentPaltform = new WebLinkManager();
                // } else {
                this.currentPaltform = new EditorPlatform();
                // }
                break
        }
        window["SDK"] = this.currentPaltform
        if (JSB) {
            this.getNativeCode((code: string) => {
                if (code != this.currentPaltform.nativeCode) {

                    return
                }
            })
        }
        // 如果不行我只能申诉了，个税APP上可以直接申诉的，但对公司有无影响我就不知道了，先告知你一下哈
        // if (PlatformManager.currentPlatform == Platform.WEB_LINK) {
        //     if (window.location.href !== 'https:game2.sfplay.net/xxx_assets/externlink/') {

        //         return
        //     }
        // }
        this.initSdk();
    }
    initSdk(args?: any, callback?: Function) {
        if (!this.currentPaltform) this.currentPaltform = new EditorPlatform();
        this.currentPaltform.initSdk()
    }
    createGameClubButton(rect, callback) {
        console.log("游戏圈 回调1")
        if (this.currentPaltform.createGameClubButton) {
              console.log("游戏圈 回调2")
            return this.currentPaltform.createGameClubButton(rect, callback);
        }
    }
    showBanner(args?: any, callback?: Function) {
        this.currentPaltform.showBanner(args, callback)
    }
    shark(args?: any, callback?: Function) {
        this.currentPaltform.shark(args, callback)
    }
    hideBanner(args?: any, callback?: Function) {
        this.currentPaltform.hideBanner(args, callback)
    }
    showInsertAd(args?: any, callback?: Function) {
        this.currentPaltform.showInsertAd(args, callback)
    }
    showVideoAd(args?: any, stub?: any, callback?: Function, callbackerror?: Function) {
        this.currentPaltform.showVideoAd(args, callback, callbackerror, stub)
    }
    share(args?: any, callback?: Function) {
        this.currentPaltform.share(args, callback)
    }
    otherFun(args?: any, callback?: Function) {
        this.currentPaltform.otherFun(args, callback)
    }
    recordVideo(args?: any, callback?: Function) {
        this.currentPaltform.recordVideo(args, callback)
    }
    stopRecorderManager(args?: any, callback?: Function) {
        this.currentPaltform.stopRecorderManager(args, callback)
    }
    youmengTrack(args: any, ab: string, value: string, id: string) {
        this.currentPaltform.youmengTrack(args, ab, value, id)
    }
    hasVerify(): boolean {
        return this.currentPaltform.hasVerify()
    }
    getNativeCode(cb: Function) {
        if (this.currentPaltform.getCode) {
            this.currentPaltform.getCode(cb)
        }
    }
    canShare(): boolean {
        if (this.currentPaltform.canShare) {
            return this.currentPaltform.canShare()
        }
        return false
    }
    pauseRecord() {
        if (this.currentPaltform.pauseRecord) {
            this.currentPaltform.pauseRecord()
        }
    }

    resumeRecord() {
        if (this.currentPaltform.resumeRecord) {
            this.currentPaltform.resumeRecord()
        }
    }

    shareVideo(path: string, callback: Function) {
        this.currentPaltform.shareVideo(path, callback)
    }
    toAppStore(cb: Function) {
        if (this.currentPaltform.toAppStore) {
            this.currentPaltform.toAppStore(cb)
        }
    }
    openNotify() {
        if (this.currentPaltform.openNotify) {
            this.currentPaltform.openNotify();
        }
    }
    shareImg(arg: string, callback: Function) {
        if (this.currentPaltform.shareImg) {
            this.currentPaltform.shareImg(arg, callback)
        }
    }
    addCollect(callback?: Function) {
        if (this.currentPaltform.addCollect) {
            this.currentPaltform.addCollect(callback)
        }
    }

    addDesktop(callback?: Function) {
        if (this.currentPaltform.addDesktop) {
            this.currentPaltform.addDesktop(callback);
        }
    }

    checkSideBar(callback?: Function) {
        if (this.currentPaltform.checkSideBar) {
            this.currentPaltform.checkSideBar(callback);
        }
    }

    receptionListen(callback?: Function) {
        if (this.currentPaltform.receptionListen) {
            this.currentPaltform.receptionListen(callback);
        }
    }

    jumpSidebar(callback?: Function) {
        if (this.currentPaltform.jumpSidebar) {
            this.currentPaltform.jumpSidebar(callback);
        }
    }

    reportEvent(eventId: string, data: Object) {
        if (this.currentPaltform.reportEvent) {
            this.currentPaltform.reportEvent(eventId, data);
        }
    }
}